
/**
 * 这是一个用于封装所有与用户收货地址相关的 API 请求的模块。
 * 假设您已经有一个封装好的 axios 实例，例如:
 * import instance from '@/utils/request';
 */
import instance from '@/utils/request';

/**
 * 获取用户的收货地址列表
 * @returns {Promise<any>}
 */
export const getAddressList = () => {
    // 后台接口: GET /back/address/list
    return instance.get('/back/orders/address/list');
};

/**
 * 添加一个新的收货地址
 * @param {object} data - 地址实体对象，包含 receiverName, receiverMobile, province, city, district, detailAddress, isDefault 等字段
 * @returns {Promise<any>}
 */
export const addAddress = (data) => {
    // 后台接口: POST /back/address
    return instance.post('/back/orders/address', data);
};

/**
 * 更新一个已有的收货地址
 * @param {number|string} addressId - 要更新的地址ID
 * @param {object} data - 更新后的地址实体对象
 * @returns {Promise<any>}
 */
export const updateAddress = (addressId, data) => {
    // 后台接口: PUT /back/address/{addressId}
    return instance.put(`/back/orders/address/${addressId}`, data);
};

/**
 * 根据地址ID删除一个收货地址
 * @param {number|string} addressId - 要删除的地址ID
 * @returns {Promise<any>}
 */
export const deleteAddressById = (addressId) => {
    // 后台接口: DELETE /back/address/{addressId}
    return instance.delete(`/back/orders/address/${addressId}`);
};

/**
 * 设置某个地址为默认地址
 * @param {number|string} addressId - 要设置为默认的地址ID
 * @returns {Promise<any>}
 */
export const setDefaultAddressApi = (addressId) => {
    // 后台接口: PUT /back/address/default/{addressId}
    return instance.put(`/back/orders/address/default/${addressId}`);
};
